package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28779
 * Date: 2023-08-18
 * Time: 10:52
 */
public class Demo10 {
    public static void main(String[] args) {
        Thread b = new Thread(()->{
            for (int i = 0; i < 5; i++) {
                System.out.println("hello b");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("b 结束了");
        });
        Thread a = new Thread(() ->{
            for (int i = 0; i < 3; i++) {
                System.out.println("hello a");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    //throw new RuntimeException(e);
                    e.printStackTrace();
                }
            }
            try {
                //如果 b 此时还没执行完毕，b.join 就会产生阻塞的情况。
                b.join(3000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("a 结束了");
        });
        b.start();
        a.start();
    }
}
